package com.wyp168.juc;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName testJucAutomic
 * @Description 测试juc相关原子性操作
 * @Author wyp168
 * @Date 2022/6/28 17:01
 */
public class testJucAtomic {
    public static void main(String[] args) {
        atomicDemo atomicDemo = new atomicDemo();
        for (int i = 0; i < 10; i++) {
            new Thread(atomicDemo).start();
        }
    }
}

class atomicDemo implements Runnable{
    AtomicInteger atomicInteger = new AtomicInteger();

    public int addTest() {
        return atomicInteger.getAndIncrement();
    }

    @Override
    public void run() {
        try {
            Thread.sleep(200);
        }catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + ":" + addTest());
    }
}
